function construct_slider(elements, prev, next, current) {
	var current_item = current;
	var total_items = 0;
	var waiting = 0;
	var e_width = 0;
	var e_margin = 0;
	
	this.list = elements;
	
	this.getCurrent = function(){
		return current_item;
	}
	init();
	bindNav(prev, next);
	function init(){
		e_margin = $('>li', this.list).css('margin-left');
		e_width = $('>li', this.list).width();
		total_items = $('>li', this.list).size();
		$('>li', this.list).hide();
		//alert($('>li', this.list).size());
		this.list.find('li:eq(' + (current + 0) + ')').show();
	}
	
	function bindNav(pre, nex){
		preFunction = function(e){
			e.preventDefault();
			prev_item();
		};
		$(pre).click(preFunction);
		
		nextFunction = function(e){
			e.preventDefault();
			next_item();
		};
		$(nex).click(nextFunction);
		
		$(document.documentElement).keypress(function (event) {
			  // handle cursor keys
			  console.log(event.keyCode);
			if (event.keyCode == 40) {
				preFunction(event)
			 }
			if(event.keyCode == 38) {
				nextFunction(event)
			}
		});
	}
	
	function next_item(){
		if(waiting || current_item == total_items - 1) return;
		waiting=1;
		$('>li:eq(' + (current_item + 1) + ')', this.list).css('opacity', '0.0').show().animate({marginLeft: e_margin , opacity: '1.0'}, 1000);
		$('>li:eq(' + (current_item + 0) + ')', this.list).animate({
			marginLeft: "-" + (e_width) + "px", opacity: '0.0'
		  }, 1000, function(){update_state(+1);});
	}
	
	function prev_item(){
		if(waiting || current_item == 0) return;
		waiting=1;
		this.list.find('>li:eq(' + (current_item + 0) + ')').animate({
			opacity: '0.0'
		  }, 1000);
		this.list.find('>li:eq(' + (current_item - 1) + ')')
			.css('margin-left' , '-' + e_width + 'px').css('opacity', '0.0')
			.show()
			.stop()
			.animate({marginLeft: e_margin , opacity: '1.0'}, 1000, function(){
				update_state(-1);});;
	}
	
	function update_state(delta){
		if(delta == 1){
			$('>li:eq(' + (current_item + 0) + ')', this.list).hide().css('margin-left', e_margin).css('opacity', 1.0);
		} else if(delta == -1){
			$('>li:eq(' + (current_item + 0) + ')', this.list).hide();
		}
		current_item+=delta;
		waiting=0;
	}
	return this;
}